package com.atguigu.bean.zqk.bean.servlet;

import com.atguigu.bean.zqk.bean.bean.User;
import com.atguigu.bean.zqk.bean.service.UserService;
import com.atguigu.bean.zqk.bean.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class Login1Servlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        request.setCharacterEncoding("utf-8");

        String username = request.getParameter("username");
        String password = request.getParameter("password");
//        String email = request.getParameter("email");

        UserService userService = new UserServiceImpl();
        User user = userService.login(username,password);

        if (user == null) {
            request.getRequestDispatcher("/pages/user/login.html").forward(request, response);
//            "/pages/user/login.html").forward(request, response);
        } else {
            response.sendRedirect(request.getContextPath()+"/pages/user/login_success.html");
        }



    }
}
